#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'作业'

import re

def is_valid_email(addr):
    if re.match(r'[a-z\.]+@[a-z]+(\.com)$',addr):
        return True
    else:
        return False


assert is_valid_email('someone@gmail.com')
assert is_valid_email('bill.gates@microsoft.com')
assert not is_valid_email('bob#example.com')
assert not is_valid_email('mr-bob@example.com')
print('ok')

def name_of_email(addr):
    if re.match(r'^\<',addr):
        s = re.match(r'(^\<)([\w\s]+)(\>)',addr).groups()
        return s[1]
    else:
        s = re.match(r'(\w+)(\@)', addr).groups()
        return s[0]

# 测试:
assert name_of_email('<Tom Paris> tom@voyager.org') == 'Tom Paris'
assert name_of_email('tom@voyager.org') == 'tom'
print('ok')